<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Contact form</title>
<style>
body{ margin:10px; font-family:Arial, Helvetica, sans-serif; font-size:14px;}
input{font-size:14px;}
.error {font-size:14px; font-weight:bold; color:#FF0000;}
p{margin:5px; font-size:14px; color:#666666}
</style>
</head>

<body>
<!-- The contact form starts from here-->
<?php
// baza bilan boglanamiz emaillarni olish uchun
include("../admin/db.php");
///// contactni olish
$result_contact = mysql_query("SELECT tel, email, tel2, email2, hamkor FROM contact");
if (!$result_contact)
{ echo "<p>Contact jadvalidan malumotlar olinmadi, xatolik</p>"; }
$row_contact = mysql_fetch_object($result_contact);
///// contact finish

if(isset($_POST['send']))
{
$name = $_POST['name'];
$youremail = $_POST['youremail'];
$shahar = $_POST['shahar'];
$message = $_POST['message'];
$spamcheck = $_POST['spamcheck'];

	if(trim($name) == '') 
	{ $error = 'iltimos, ismingizni yozing'; }
	else if(trim($youremail) == '') 
	{ $error = 'iltimos, emailni yozing'; } 
	else if(trim($shahar) == '') 
	{ $error = 'iltimos, shaharni yozing!'; }
	else if(trim($message) == '') 
	{ $error = 'iltimos maktubni yozing'; }
	else if(trim($spamcheck) != '5') 
	{ $error = 'Xato AntiSpam: iltimos 5 sonini yozing';}
	if($error == '')
	{
		if(get_magic_quotes_gpc())
		{
		$message = stripslashes($message);
		}
		// bazadan emailni olamiz
		$to = $row_contact->email;
		$to2 = $row_contact->email2;
		 // sarlavha              
		$subject = "Saytingizdan maktub --- ";
		// maktub
		$msg     = "ism: $name \r\n E-Mail: $youremail \r\n Shahar: $shahar \r\n" . "Maktub: \r\n$message";
						
		mail($to, $subject, $msg, "From: $youremail \r\n  Content-type: text/html; charset=utf-8 \r\n");
		mail($to2, $subject, $msg, "From: $youremail \r\n Reply-To: $youremail\r\nReturn-Path: $youremail\r\n");
?>
        <div style="text-align:center; font-size:18px; color:#0099CC;">
         Rahmat sizga <?=$name;?> <br>maktubingiz jo'natildi!<br>
         Agar yana yubormoqchi bo'lsangiz, <a href="contact_form.php">bu yerni bosing</a>
        </div>
<?php
	}
}

if(!isset($_POST['send']) || $error != '')
{
?>
<span class="error"> <?=$error;?> </span>
<form  method="post" name="myform" action="" style="margin-left:50px;">
<TABLE border="0">
    <tr>
     <td><p>ism:</p></td>
      <td>
       <input name="name" type="text" size="35" value="<?=$name;?>" /></td>
   </tr>
   <tr>
     <td><p>Email:</p></td>
     <td><input name="youremail" type="text" size="35" value="<?=$youremail;?>" /></td>
	</tr>
    <tr>
     <td><p>Shahar:</p></td>
     <td><input name="shahar" type="text" size="35" value="<?=$shahar;?>" /></td>
	</tr>
</TABLE> 
		<p>Maktub:<br>
		  <textarea name="message" cols="45" rows="6" style=" font-family:Arial, Helvetica"><?=$message;?></textarea>
		<p class="malumot">Anti spam: Bu yerga 5 sonini yozing:
		<input name="spamcheck" type="text" size="4" value="<?=$spamcheck;?>" /></p>
        <br />
        <input name="send" type="submit" value="Maktubni yuborish" />
</form>

<?php
}
?>
</body>
</html>